package com.mightykiwi.controllers;

import java.util.ArrayList;
import java.util.List;

import com.mightykiwi.beans.Product;
import com.mightykiwi.beans.UserMK;
import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import com.restfb.json.JsonArray;
import com.restfb.json.JsonObject;

public class WishlistController {

	private static WishlistController instance;

	private WishlistController() { }

	public static WishlistController getInstance() {
		if(instance == null)
			instance = new WishlistController();
		return instance;
	}

	public List<Product> getWishlist(UserMK user, String contact_sn, String contact_id) {
		List<Product> products = new ArrayList<Product>();
		List<String> keywordMovies = new ArrayList<String>();
		List<String> keywordMusic = new ArrayList<String>();
		List<String> keywordBooks = new ArrayList<String>();

		FacebookClient fbClient = new DefaultFacebookClient(user.getAccess_token());

		JsonObject likesConnection = fbClient.fetchObject(contact_id + "/likes", JsonObject.class);
		JsonArray likesJsonArray = likesConnection.getJsonArray("data");
		JsonObject moviesConnection = fbClient.fetchObject(contact_id + "/movies", JsonObject.class);
		JsonArray moviesJsonArray = moviesConnection.getJsonArray("data");
		JsonObject musicConnection = fbClient.fetchObject(contact_id + "/music", JsonObject.class);
		JsonArray musicJsonArray = musicConnection.getJsonArray("data");
		JsonObject booksConnection = fbClient.fetchObject(contact_id + "/books", JsonObject.class);
		JsonArray booksJsonArray = booksConnection.getJsonArray("data");

		int length = moviesJsonArray.length();
		for(int i = 0; i < length; i++) {
			JsonObject obj = (JsonObject)moviesJsonArray.get(i);
			keywordMovies.add(obj.getString("name"));
		}

		length = musicJsonArray.length();
		for(int i = 0; i < length; i++) {
			JsonObject obj = (JsonObject)musicJsonArray.get(i);
			keywordMusic.add(obj.getString("name"));
		}

		length = booksJsonArray.length();
		for(int i = 0; i < length; i++) {
			JsonObject obj = (JsonObject)booksJsonArray.get(i);
			keywordBooks.add(obj.getString("name"));
		}



		return products;
	}
}
